﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Ama.BugTracker.Web.Handler
{
    /// <summary>
    /// QueryUserListHandler 的摘要说明
    /// </summary>
    public class QueryUserListHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            DataTable table = UserSql.QueryAllUserList();
            JsonSerializer json = new JsonSerializer();
            json.NullValueHandling = NullValueHandling.Include;
            json.ObjectCreationHandling = ObjectCreationHandling.Replace;
            json.MissingMemberHandling = MissingMemberHandling.Ignore;
            json.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

            json.Converters.Add(new DataTableConverter());

            StringWriter sw = new StringWriter();
            JsonTextWriter writer = new JsonTextWriter(sw);
            writer.Formatting = Formatting.Indented;

            writer.QuoteChar = '"';
            json.Serialize(writer, table);

            string output = sw.ToString();
            writer.Close();
            sw.Close();

            context.Response.Write(output);

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}